using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace Loading.Models
{ 
    public class BrassLotRepository : IBrassLotRepository
    {
        LoadingContext context = new LoadingContext();

        public IQueryable<BrassLot> All
        {
            get { return context.BrassLots; }
        }

        public IQueryable<BrassLot> AllIncluding(params Expression<Func<BrassLot, object>>[] includeProperties)
        {
            IQueryable<BrassLot> query = context.BrassLots;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public BrassLot Find(int id)
        {
            return context.BrassLots.Find(id);
        }

        public void InsertOrUpdate(BrassLot brasslot)
        {
            if (brasslot.BrassLotId == default(int)) {
                // New entity
                context.BrassLots.Add(brasslot);
            } else {
                // Existing entity
                context.Entry(brasslot).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var brasslot = context.BrassLots.Find(id);
            context.BrassLots.Remove(brasslot);
        }

        public void Save()
        {
            context.SaveChanges();
        }
    }

    public interface IBrassLotRepository
    {
        IQueryable<BrassLot> All { get; }
        IQueryable<BrassLot> AllIncluding(params Expression<Func<BrassLot, object>>[] includeProperties);
        BrassLot Find(int id);
        void InsertOrUpdate(BrassLot brasslot);
        void Delete(int id);
        void Save();
        
       
    }
}